<?php
$path = $_SERVER['DOCUMENT_ROOT'];
require_once "$path/public/Products.php";
include "$path/view/head.php";
$product = new Products();
$category_id = $_GET["id"];
$current_page = empty($_GET["current_page"]) ? 1 : $_GET["current_page"];
$page_size = empty($_GET["page_size"]) ? 20 : $_GET["page_size"];
$product->init($category_id, $current_page, $page_size);
$type = !empty($_GET["type"]) ? "type=" . $_GET["type"] : "";
$ppid = !empty($_GET["pid"]) ? "pid=" . $_GET["pid"] : "";
$id = !empty($_GET["id"]) ? "id=" . $_GET["id"] : "";
include "$path/view/banner.php";
include "$path/view/left.php"; ?>
<div class="pro_list wow_list">
    <ul>
        <?php
        foreach ($product->productDatas["dataList"] as $val) {
            ?>
            <li class="animate__animated animate__backInUp" data-wow-delay="0s"
                style=" text-align: center;vertical-align: middle;margin: 1px;">
                <a style=" text-align: center;vertical-align: middle;"
                   href="/<?php echo $basepath.($cms->is_html?"/html/products/product_detail".$val["idProduct"].".html":"/view/product_detail.php??&detail_id=".$val["idProduct"] . "&$type&$ppid&$id") ?>">
                    <div class="img">
                        <img src="/<?php echo $basepath ?>/assert/images/hangye.jpg"></div>
                    <div class="text">
                        <div class="box">
                            <h4><?php echo $val["productName"] ?></h4>
                            <p><?php echo substr($val["productDesc"], 0, 200) . "..." ?></p>
                            <span class="btn">详情</span></div>
                    </div>
                </a>
            </li>
        <?php } ?>
    </ul>

</div>
<div class="page">
    <ul>
        <?php
        if ($product->currentPage > 1) {
            if ($cms->is_html) {
                $p = $product->currentPage - 1;
                echo "<li><a href=\"/$basepath/product$id" . ($p == 1 ? "" : "_$p") . ".html\">上一页</a></li>";
            } else {

                echo "<li><a href=\"/$basepath/view/products.php?$type&$pid&$id&page_size =20&current_page =" . ($product->currentPage - 1) . "\">上一页</a></li>";
            }
        }
        $total = $product->totalPages;
        for ($index = 1; $index <= $total; $index++) {
            if ($product->currentPage == $index) {
                echo "<li class='thisclass'><span>$index</span></li>";
            } else {
                if ($cms->is_html) {
                    echo "<li><a href=\"/$basepath/product$id" . ($index == 1 ? "" : "_$index") . ".html\">$index</a></li>";
                } else {

                    echo "<li><a href=\"/$basepath/view/products.php?$type&$pid&$id&page_size=20&current_page=$index\">$index</a></li>";
                }
            }
        }
        if ($product->totalPages > 1 && $product->currentPage < $product->totalPages) {
            if ($cms->is_html) {
                echo "<li><a href=\"/$basepath/product$id" . "_" . ($product->currentPage + 1) . ".html\">下一页</a></li>";
            } else {
                echo "<li><a href=\"/$basepath/view/products.php?$type&$pid&$id&page_size=20&current_page=" . ($product->currentPage + 1) . "\">下一页</a></li>";
            }
        }
        if ($cms->is_html) {
            echo "<li><a href=\"/$basepath/product$id" . "_" . $product->totalPages . ".html\">尾页</a></li>";
        } else {
            echo " <li><a href=\"/$basepath/view/products.php?$type&$pid&$id&page_size=20&current_page=$product->totalPages\" class=\"c-nav ease moye\">尾页</a></li>";
        }
        ?>

    </ul>
</div>

</div>
</div>
</div>
<?php include "$path/view/recommend.php"; ?>
<?php
include "$path/view/footer.php"; ?>
